package com.w3c.pragmatic.controller;

import com.w3c.pragmatic.common.annotation.LogAspect;
import com.w3c.pragmatic.common.enums.OperatorEnum;
import com.w3c.pragmatic.domain.Response;
import com.w3c.pragmatic.domain.req.ProductPageReq;
import com.w3c.pragmatic.domain.res.PageRes;
import com.w3c.pragmatic.domain.res.ProductInfoRes;
import com.w3c.pragmatic.entity.ProductInfo;
import com.w3c.pragmatic.service.IProductInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 产品信息表 前端控制器
 *
 * @author wangdong
 * @since 2025-02-20
 */
@RestController
@RequestMapping("/product")
@Api(tags = "产品信息表控制层ProductInfoController")
public class ProductInfoController {

  @Resource private IProductInfoService productInfoService;

  /**
   * 分页-列表信息-LambdaQueryWrapper
   *
   * @return List<ProductInfo>
   */
  @ApiOperation(value = "分页列表信息-LambdaQueryWrapper", httpMethod = "POST")
  @RequestMapping(
      value = "/lambdaPage",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public Response<PageRes<ProductInfoRes>> findProductPageLambda(@RequestBody ProductPageReq req) {
    return Response.ok(productInfoService.findProductPageLambda(req));
  }

  /**
   * 分页-列表信息-baseMapper
   *
   * @return List<ProductInfo>
   */
  @ApiOperation(value = "分页列表信息-BaseMapper", httpMethod = "POST")
  @RequestMapping(
      value = "/mapperPage",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public Response<PageRes<ProductInfoRes>> findProductPageMapper(@RequestBody ProductPageReq req) {
    return Response.ok(productInfoService.findProductPageMapper(req));
  }

  /**
   * 查询产品列表
   *
   * @return List<ProductInfo>
   */
  @ApiOperation(value = "查询产品列表", httpMethod = "POST")
  @RequestMapping(
      value = "/find/{productType}",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @LogAspect(desc = "查询产品列表", operateType = OperatorEnum.SELECT)
  public Response<List<ProductInfo>> findProductList(
      @ApiParam("产品类型") @PathVariable String productType) {
    return Response.ok(productInfoService.findList(productType));
  }

  /**
   * 查询产品详情
   *
   * @return List<ProductInfo>
   */
  @ApiOperation(value = "查询产品详情", httpMethod = "GET")
  @RequestMapping(
      value = "/detail/{productCode}",
      method = RequestMethod.GET,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public Response<ProductInfo> getProductInfo(@ApiParam("产品编码") @PathVariable String productCode) {
    return Response.ok(productInfoService.getByProductCode(productCode));
  }
}
